package com.cj.service.impl;

import com.cj.dao.ClassStudentDao;
import com.cj.po.PageInfo;
import com.cj.po.Student;
import com.cj.service.ClassStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ClassStudentServiceImpl implements ClassStudentService {
    @Autowired
    private ClassStudentDao classStudentDao;

   @Override
   public PageInfo<Class> findPageInfo(Integer c_classid, String className, String counsellor, Integer s_studentid, String s_name, String s_phone, Integer s_dormitoryid, Integer pageIndex, Integer pageSize) {
    PageInfo<Class> pi = new PageInfo<Class>();
    pi.setPageIndex(pageIndex);
    pi.setPageSize(pageSize);

    //获取总条数
    Integer totalCount = classStudentDao.totalCount(s_name, s_studentid, c_classid, className);
    if (totalCount > 0) {
        pi.setTotalCount(totalCount);
        //每一页显示学生信息数
        //currentPage = (pageIndex-1)*pageSize  当前页码数减1*最大条数=开始行数

        List<Class> classList = classStudentDao.getClassStudentList(s_name, s_studentid, c_classid, className,
                (pageIndex - 1) * pageSize, pageSize);
        if (classList != null && !classList.isEmpty()) {
            pi.setList(classList);
        }
    }
    return pi;
}

//    @Override
//    public PageInfo<Class> findPageInfo(String s_name, Integer s_studentid, Integer c_classid, String s_classname, Integer pageIndex, Integer pageSize) {
//        PageInfo<Class> pi = new PageInfo<Class>();
//        pi.setPageIndex(pageIndex);
//        pi.setPageSize(pageSize);
//        //获取总条数
//        Integer totalCount = classStudentDao.totalCount(s_name, s_studentid, c_classid, s_classname);
//        if (totalCount > 0) {
//            pi.setTotalCount(totalCount);
//            //每一页显示学生信息数
//            //currentPage = (pageIndex-1)*pageSize  当前页码数减1*最大条数=开始行数
//            List<Class> classList = classStudentDao.getClassStudentList(s_name, s_studentid, c_classid, s_classname,
//                    (pageIndex - 1) * pageSize, pageSize);
//            if (classList != null && !classList.isEmpty()) {
//                pi.setList(classList);
//            }
//        }
//        return pi;
//    }

    @Override
    public List<Class> getAll2() {
       List<Class> classList = classStudentDao.getAll2();
       return classList;
    }

}
